﻿using CoreShop.Library;
using CoreShop.Model;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace CoreShop.App
{
    public partial class UIDishPrintbillTemplatePool : UIUserControl
    {
        public UIDishPrintbillTemplatePool()
        {
            InitializeComponent();
        }

        public corecmsprintbilltemplate Info { get; set; }
        public UIDishPrintbillTemplatePool(corecmsprintbilltemplate info)
        {
            InitializeComponent();
            Info = info;
            selectedFlag.Checked = info.selectedFlag;
        }

        public UIButton CreateButton(string text)
        {
            UIButton btn = new UIButton();
            btn.BackColor = System.Drawing.Color.White;
            btn.Cursor = System.Windows.Forms.Cursors.Hand;
            btn.FillColor = System.Drawing.Color.White;
            btn.FillColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(155)))), ((int)(((byte)(40)))));
            btn.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(227)))), ((int)(((byte)(175)))), ((int)(((byte)(83)))));
            btn.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(176)))), ((int)(((byte)(124)))), ((int)(((byte)(32)))));
            btn.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(248)))), ((int)(((byte)(229)))));
            btn.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            btn.ForeColor = System.Drawing.Color.Black;
            btn.ForeHoverColor = System.Drawing.Color.Black;
            btn.ForePressColor = System.Drawing.Color.Black;
            btn.ForeSelectedColor = System.Drawing.Color.Black;
            btn.MinimumSize = new System.Drawing.Size(1, 1);
            btn.Name = text;
            btn.Radius = 9;
            btn.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
            btn.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(227)))), ((int)(((byte)(175)))), ((int)(((byte)(83)))));
            btn.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(176)))), ((int)(((byte)(124)))), ((int)(((byte)(32)))));
            btn.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(189)))), ((int)(((byte)(0)))));
            btn.Size = new System.Drawing.Size(58, 25);
            btn.Style = Sunny.UI.UIStyle.Custom;
            btn.StyleCustomMode = true;
            btn.Text = text;
            btn.Parent = this;
            return btn;
        }

        private void UIFDishPinterSetupItem_Paint(object sender, PaintEventArgs e)
        {
            if (Selected)
            {
                e.Graphics.FillRectangle(SelectedColor, 0, 0, Width, Height);
            }
            if (Info == null) return;
            using (Font font = new System.Drawing.Font("微软雅黑", 10.5F))
            {
                e.Graphics.DrawString(Info.name, font, Color.Black, new Rectangle(50, 0, Width, Height), ContentAlignment.MiddleLeft);
                e.Graphics.DrawString(EnumHelper.GetEnumByValue<GlobalEnumVars.PrintbillType>(Info.billtypeId), font, Color.Black, new Rectangle(170, 0, 118, Height), ContentAlignment.MiddleLeft);
                e.Graphics.DrawString(EnumHelper.GetEnumByValue<GlobalEnumVars.foodPrintType>(Info.foodPrintType), font, Color.Black, new Rectangle(260, 0, 119, Height), ContentAlignment.MiddleCenter);
                //e.Graphics.DrawString(Info.foodSortName, font, Color.Black, new Rectangle(485, 0, 119, Height), ContentAlignment.MiddleCenter);                
                //e.Graphics.DrawString(Info.printCount, font, Color.Black, new Rectangle(590, 0, 119, Height), ContentAlignment.MiddleCenter);
            }
        }

        public event EventHandler CheckBoxChecked;
        private void uiCheckBox1_CheckedChanged(object sender, System.EventArgs e)
        {
            if (Info != null)
            {
                Info.selectedFlag = selectedFlag.Checked;
                CheckBoxChecked?.Invoke(Info, e);
            }            
        }

        public bool Checked
        {
            get => selectedFlag.Checked;
            set => selectedFlag.Checked = value;
        }

        private bool selected = false;
        public bool Selected
        {
            get => selected;
            set
            {
                selected = value;
                Invalidate();
            }
        }

        private Color selectedColor = Color.FromArgb(221, 221, 221);
        public Color SelectedColor
        {
            get => selectedColor;
            set
            {
                selectedColor = value;
                Invalidate();
            }
        }

        public event EventHandler ModifyItemClick;
        private void btn_Click(object sender, EventArgs e)
        {
            ModifyItemClick?.Invoke(Info, e);
        }

        public event EventHandler TableClick;
        private void UIDishSchemeDetailItem_Click(object sender, System.EventArgs e)
        {
            Selected = true;
            foreach (var item in Parent.GetControls<UIDishPrintbillTemplatePool>())
            {
                if (item.Equals(this)) continue;

                item.Selected = false;
            }
            TableClick?.Invoke(this, e);
        }
    }
}
